home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / ipc / sub_climesg.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  765b  |  39 lines

  1. #include    <stdio.h>
  2. #include    "mesg.h"
  3.  
  4. Mesg    mesg;
  5.  
  6. client(ipcreadfd, ipcwritefd)
  7. int    ipcreadfd;
  8. int    ipcwritefd;
  9. {
  10.     int    n;
  11.  
  12.     /*
  13.      * Read the filename from standard input, write it as
  14.      * a message to the IPC descriptor.
  15.      */
  16.  
  17.     if (fgets(mesg.mesg_data, MAXMESGDATA, stdin) == NULL)
  18.         err_sys("filename read error");
  19.  
  20.     n = strlen(mesg.mesg_data);
  21.     if (mesg.mesg_data[n-1] == '\n')
  22.         n--;            /* ignore newline from fgets() */
  23.     mesg.mesg_len = n;
  24.     mesg.mesg_type = 1L;
  25.     mesg_send(ipcwritefd, &mesg);
  26.  
  27.     /*
  28.      * Receive the message from the IPC descriptor and write
  29.      * the data to the standard output.
  30.      */
  31.  
  32.     while ( (n = mesg_recv(ipcreadfd, &mesg)) > 0)
  33.         if (write(1, mesg.mesg_data, n) != n)
  34.             err_sys("data write error");
  35.  
  36.     if (n < 0)
  37.         err_sys("data read error");
  38. }
  39.